package wili.insertCode;

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import wili.a.Refs;
import wili.c.src.ClsObj;
import wili.c.src.JaClassInds;
import wili.c.src.JaIndsMap;
import wili.c.src.JaMethodInds;

/**
 * 源代码的各个组成部分
 *
 * @author weila 2022年6月23日
 */
public class ClassPart {
	Map<Integer, Object> bracketMap = new HashMap<>();

	Map<Integer, MethodPart> methodMap = new HashMap<>();

	Map<Integer, FieldsPart> fieldsMap = new HashMap<>();

	JfilePart file;

	public final ClsObj cls;

	public String cname;
	String headSt;//class 行上直到左花括之间的内容。
	final String type;//class|interface|enum

	public String toString() {
		return cname;
	}

	public ClassPart(JaClassInds inds, JfilePart file, Cont cont) {
		String src = file.src_blankComment;
		this.type = inds.type;
		this.file = file;
		this.cname = inds.name;
		int ind = inds.startInd + src.substring(inds.startInd).indexOf("{");
		headSt = src.substring(inds.startInd, ind);
		//System.out.println(inds.src0.substring(inds.startInd));
		if (Refs.skipClassObj()) {
			if (file.cls.clsName.endsWith("." + cname)) {
				this.cls = file.cls;
			} else {
				this.cls = null;
			}
		} else {
			if (file.cls.value.getSimpleName().equals(cname)) {
				this.cls = file.cls;
			} else {
				this.cls = null;
			}
		}
		JaIndsMap sonMap = inds.sonMap;
		List<JaMethodInds> mm = sonMap.getMethods();
		for (JaMethodInds ele : mm) {
			if (ele.isAbstractMethod)
				continue;
			if (ele.method instanceof Constructor<?>)
				continue;
			methodMap.put(ele.startInd, new MethodPart(ele, this, cont));
		}
	}

	public boolean isClass() {
		return type.equals("class");
	}

	public List<MethodPart> findMethods(Set<String> names) {
		return null;
	}
}
